package tool;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.sql.Date;





//@Deprecated
public class DateUtil {

public java.sql.Date	start; 
public java.sql.Date 	end;
    

    /**
     * 以当前时间为基准 到 N天后的时间 用于数据库按天来查询查询 注意可以为负数
     * 如：2016-06-30   2016-07-01
     */
    public DateUtil(int latterDays)
    {
    	if(latterDays>0){
	    	Calendar cal=Calendar.getInstance();
	    	cal.set(Calendar.HOUR_OF_DAY, 0);
			cal.set(Calendar.MINUTE, 0);
			cal.set(Calendar.SECOND, 0);
			this.start = new java.sql.Date(cal.getTimeInMillis());	
	    	cal.setTime(start);
	    	cal.add(Calendar.DATE, latterDays);
	    	this.end= new java.sql.Date(cal.getTimeInMillis());
    	}else{
    		Calendar cal=Calendar.getInstance();
	    	cal.set(Calendar.HOUR_OF_DAY, 0);
			cal.set(Calendar.MINUTE, 0);
			cal.set(Calendar.SECOND, 0);
			this.end = new java.sql.Date(cal.getTimeInMillis());	
	    	cal.setTime(end);
	    	cal.add(Calendar.DATE, latterDays);
	    	this.start= new java.sql.Date(cal.getTimeInMillis());
    	}
    }
   

//    test
    public static void main(String[] args){
    	DateUtil u = new DateUtil(20);
    	Date d1 = u.start;
    	Date d2 = u.end;
    	System.out.println(d1.toString());
    	System.out.println(d2.toString());
//    	System.out.println(d2.getHours());
    	
    	System.out.println(new java.sql.Date(System.currentTimeMillis()).toString());
    }
   
    
}